package cn.fighter3.service.node;

import cn.fighter3.entity.node.Cnbook;
import cn.fighter3.entity.node.People;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;

import java.util.List;

public interface CnbookDao extends Neo4jRepository<Cnbook,String> {
    //查询--按名字
    List<Cnbook> findByTitle(String title);
    Cnbook findByName(String name);
    //查询--按id
    Cnbook findByBookId(String id);
    //模糊查询
//    @Query("match(n:Cnbook) where n.title =~'.*{name}.*' return n")
//    Cnbook find(@Param(value="name") String name);
    List<Cnbook> findByTitleLike(String name);

    //删除
    void deleteByBookId(String id);
    @Query("match (n:Cnbook) where n.title=$title detach delete n")
    void deleteByTitle(String title);

    //更新修改
    @Query("match (n:Cnbook) where n.bookId = $id set n.title = $title, n.M_PUBLISHER = $publish, n.M_CALL_NO = $call, n.m_PUB_YEAR = $year return n")
    Cnbook updateByNode(String id,String title,String publish,String call,String year);

    //@Query("match (n:Cnbook) return n limit 25")
    //MATCH (b:Cnbook) WITH b,SIZE((b)-[:Authorof]->()) as authorCnt ORDER BY authorCnt DESC LIMIT 20 MATCH (b)-[:Authorof]->(a) RETURN b, a
    //match (a:Cnbook)-[r]->(b) return a,count(r) order by count(r) DESC limit 20
    @Query("match (a:Cnbook)-[r]->(b) return a,count(r) order by count(r) DESC limit 20")
    List<Cnbook> all1();

    //查询关系数量
    //MATCH (n:Cnbook {bookId:'1009'})-[]-() RETURN count(*);
    //"profile match (n:Cnbook) where n.bookId = $id return size((n)-[r:Authorof]->())
    @Query("MATCH (n:Cnbook {bookId:$id})-[]-() RETURN count(*)")
    Integer countcn(String id);

}
